﻿

Namespace ind.crypt
    ''' <summary>
    ''' class to encapsulate the data of file used in listview
    ''' </summary>
    ''' <remarks></remarks>
    'Public Class CryptFileObj1
    ' ''' <summary>
    ' ''' id in database
    ' ''' </summary>
    ' ''' <remarks></remarks>
    'Public id As Integer
    ' ''' <summary>
    ' ''' file name
    ' ''' </summary>
    ' ''' <remarks></remarks>
    'Public FileName As String
    ' ''' <summary>
    ' ''' return filename without Crypt extension
    ' ''' WARNING: Only without cryptextension. Original extension remains
    ' ''' </summary>
    ' ''' <value></value>
    ' ''' <returns></returns>
    ' ''' <remarks></remarks>
    'Public ReadOnly Property FileNameWithoutExtension
    '    Get
    '        Return getFileNameWithoutCryptExtension(Me.FileName)
    '    End Get
    'End Property
    ' ''' <summary>
    ' ''' fullpath of the file
    ' ''' </summary>
    ' ''' <remarks></remarks>
    'Public FullPath As String
    'Private Extension_m As String
    ' ''' <summary>
    ' ''' extension of the file
    ' ''' </summary>
    ' ''' <remarks></remarks>
    'Public Property extension As String
    '    Get
    '        Return Me.Extension_m
    '    End Get
    '    Set(value As String)
    '        If value Is Nothing Then
    '            Me.Extension_m = ""
    '        Else
    '            If value.Length > 0 And value.StartsWith(".") Then
    '                Me.Extension_m = value.Remove(0, 1)
    '            Else
    '                Me.Extension_m = "" & value

    '            End If
    '        End If
    '    End Set
    'End Property
    ' ''' <summary>
    ' ''' kb size
    ' ''' </summary>
    ' ''' <remarks></remarks>
    'Private mLength As Long
    ' ''' <summary>
    ' ''' last acces of the user
    ' ''' </summary>
    ' ''' <remarks></remarks>
    'Public dateLastAccess As Date
    ' ''' <summary>
    ' ''' computer where the file was added
    ' ''' </summary>
    ' ''' <remarks></remarks>
    'Public ComputerLastAccess As String
    ' ''' <summary>
    ' ''' indicate that the file was not found in the location
    ' ''' </summary>
    'Public FileNotFound As Boolean
    ' ''' <summary>
    ' ''' Enum with the position of each column in uccryptexplorer listview
    ' ''' </summary>
    ' ''' <remarks></remarks>
    'Public Enum lvFieldEnum As Byte
    '    name = 0
    '    ''' <summary>
    '    ''' file Full path
    '    ''' </summary>
    '    path = 1
    '    type = 2
    '    Length = 3
    '    dateLastAccess = 4
    '    ComputerLastAccess = 5
    '    FileNotFound = 6
    '    datemodified = 7
    '    dateCreated = 8
    '    attributes = 9
    'End Enum

    'Public Sub New()

    'End Sub

    'Public Sub New(fileName As String, filePath As String, Extension As String, Length As Long)
    '    Me.FileName = fileName
    '    Me.FullPath = filePath
    '    Me.extension = Extension
    '    Me.mLength = Length
    'End Sub

    'Public Sub New(listViewItemSource As Windows.Forms.ListViewItem)
    '    Me.FileName = listViewItemSource.SubItems(ind.crypt.CryptFileObj.lvFieldEnum.name).Text
    '    Me.FullPath = listViewItemSource.SubItems(ind.crypt.CryptFileObj.lvFieldEnum.path).Text
    '    Me.extension = listViewItemSource.SubItems(ind.crypt.CryptFileObj.lvFieldEnum.type).Text
    '    setLenghtValueValidator(listViewItemSource.SubItems(ind.crypt.CryptFileObj.lvFieldEnum.Length).Text)
    '    Me.dateLastAccess = listViewItemSource.SubItems(ind.crypt.CryptFileObj.lvFieldEnum.dateLastAccess).Text
    '    Me.ComputerLastAccess = listViewItemSource.SubItems(ind.crypt.CryptFileObj.lvFieldEnum.ComputerLastAccess).Text
    'End Sub


    'Public Sub New(fileFI As IO.FileInfo)
    '    Me.createByFile(fileFI)
    'End Sub


    ' ''' <summary>
    ' ''' create the object based on file on disk
    ' ''' </summary>
    ' ''' <param name="file"></param>
    ' ''' <remarks></remarks>
    'Public Sub createByFile(file As IO.FileInfo)

    '    Me.FileName = file.Name
    '    Me.FullPath = file.FullName
    '    If file.Extension = "." & ind.cte.AppConst.fileCryptExtension Then
    '        Dim nameWithoutExtension As String = IO.Path.GetFileNameWithoutExtension(Me.FileName)
    '        Dim realFileextension As String = IO.Path.GetExtension(nameWithoutExtension)
    '        Me.extension = realFileextension
    '    Else
    '        Me.extension = file.Extension
    '    End If

    '    Me.mLength = file.Length
    '    Me.dateLastAccess = file.LastAccessTime
    '    If FullPath.StartsWith("\\") = True Then
    '        'It´s in a net
    '        Dim f As String = file.FullName.Remove(0, 2)
    '        Dim searchBar As Integer = f.IndexOf("\")
    '        f = f.Substring(0, searchBar)
    '        Me.ComputerLastAccess = f
    '    Else
    '        Me.ComputerLastAccess = My.Computer.Name
    '    End If
    'End Sub
    ' ''' <summary>
    ' ''' length of file. To set the value use <see cref=" setLenghtValueValidator">setLenghtValueValidator</see>
    ' ''' </summary>
    ' ''' <value></value>
    ' ''' <returns></returns>
    ' ''' <remarks></remarks>
    'Public Property length As Long
    '    Get
    '        Return Me.mLength
    '    End Get
    '    Set(value As Long)
    '        Me.mLength = value
    '    End Set
    'End Property
    ' ''' <summary>
    ' ''' validate lenght value
    ' ''' </summary>
    ' ''' <param name="lenStr"></param>
    'Public Sub setLenghtValueValidator(lenStr As String)

    '    Dim lng As Long
    '    Dim lenStrUpper As String = lenStr.ToUpper

    '    'basic value is bytes
    '    If lenStrUpper.EndsWith("Bytes") Then
    '        lenStrUpper = lenStrUpper.Replace("Bytes", "").Trim
    '        lng = CLng(lenStrUpper)
    '    ElseIf lenStrUpper.EndsWith("KB") Then
    '        lenStrUpper = lenStrUpper.Replace("KB", "").Trim
    '        lng = CLng(lenStrUpper)
    '        lng = lng * 1024 'convert to bytes

    '    ElseIf lenStrUpper.EndsWith("MB") Then
    '        lenStrUpper = lenStrUpper.Replace("MB", "").Trim
    '        lng = CLng(lenStrUpper)
    '        lng = lng * 1048576 'convert to bytes
    '    Else
    '        lng = CLng(lenStrUpper)
    '    End If

    '    Me.mLength = lng

    'End Sub



    ' ''' <summary>
    ' ''' used to facilitate the access to the values
    ' ''' </summary>
    ' ''' <param name="lvi"></param>
    ' ''' <param name="field"></param>
    ' ''' <returns></returns>
    ' ''' <remarks></remarks>
    'Public Shared Function getValueByField(lvi As Windows.Forms.ListViewItem, field As lvFieldEnum) As String

    '    If lvi Is Nothing Then
    '        Throw New Exception("You send a listviewitem nothing")
    '    End If

    '    Return lvi.SubItems(field).Text

    'End Function
    ' ''' <summary>
    ' ''' return filename without Crypt extension
    ' ''' WARNING: Only remove cryptextension
    ' ''' </summary>
    ' ''' <param name="FileNameWithExtension"></param>
    ' ''' <returns></returns>
    ' ''' <remarks></remarks>
    'Public Shared Function getFileNameWithoutCryptExtension(FileNameWithExtension As String) As String
    '    Dim extension As String = IO.Path.GetExtension(FileNameWithExtension)
    '    If extension <> ind.cte.AppConst.fileCryptExtension Then
    '        Return FileNameWithExtension
    '    Else
    '        Dim fileWithouExtension As String = FileNameWithExtension.Replace(extension, "")
    '        Return fileWithouExtension
    '    End If
    'End Function

    ' ''' <summary>
    ' ''' Check if a file is encrypted based only in final extension. 
    ' ''' </summary>
    ' ''' <param name="FileNamePath"></param>
    ' ''' <returns>True if file has ocpt extension otherwise false</returns>
    ' ''' <remarks></remarks>
    'Public Shared Function fileIsEncrypted(FileNamePath As String) As Boolean
    '    Dim extension As String = IO.Path.GetExtension(FileNamePath) 'returns with "." before
    '    If extension = "." & ind.cte.AppConst.fileCryptExtension Then
    '        Return True
    '    Else
    '        Return False
    '    End If

    'End Function

    'End Class
End Namespace